define("admin/page/manage/password", [
    "jquery",
    "vue",
    "vue-resource",
    "toastr"
], function($, Vue, VueHttp, toastr){

    Vue.use(VueHttp);

    var vm = new Vue({
        el : '#password',

        data: {
            old_password: '',
            password: '',
            password_confirmation: '',
            token: '',
        },
        
        methods: {
            sub_psw: function(){
                var self = this;
                if (this.old_password && this.password && this.password_confirmation) {
                    if (this.password == this.password_confirmation) {
                        this.$http.post("/admin/manage/password", {
                            'old_password': this.old_password,
                            'password': this.password,
                            'password_confirmation': this.password_confirmation,
                            '_token': this.token
                        })
                        .then(function(response){
                            return response.json();
                        })
                        .then(function(json){
                            if (json.ret == 0) {
                                toastr.success(json.msg);
                                setTimeout(function(){
                                    window.location.href = json.data.url;
                                },3000)
                            } else {
                                self.token = json.data.token;
                                toastr.warning(json.msg);
                            }
                        })
                        .catch(function() {
                            toastr.warning('接口请求失败');
                        });
                    } else {
                        toastr.warning('新密码两次输入不一致');
                    }
                } else {
                    toastr.warning('请填写密码');
                }
            }
        },

        mounted: function(){
            Vue.set(this, 'token', $("[name='csrf-token']").attr('content'));
        },
    });
});